<!doctype html>
<html class="x-admin-sm">

<head>
  <meta charset="UTF-8">
  <title>市级盘点</title>
  <meta name="renderer" content="webkit|ie-comp|ie-stand">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="stylesheet" href="../../css/xadmin.css">
  <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>

  <script src="../../js/app.js" type="text/javascript" charset="utf-8"></script>
  <style type="text/css">

  </style>
</head>

<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-body ">
            <!-- 盘点条件筛选 -->
            <div class="layui-collapse" lay-accordion="">
              <!-- 市级仓库盘点 -->
              <div class="layui-colla-item">
                <h2 class="layui-colla-title">本市仓库余量</h2>
                <div class="layui-colla-content layui-show">

                  <div class="layui-form">
                    <div class="layui-form-item">
                      <div class="layui-inline">
                        <label class="layui-form-label">种类选择：</label>
                        <div class="layui-input-inline">
                          <select name="category" id="category" lay-filter="category">
                            <option value="">直接选择或搜索选择</option>
                            <!-- category 类型 -->
                          </select>
                        </div>
                      </div>
                    </div>
                    <div class="layui-form-item">
                      <div class="layui-inline">
                        <label class="layui-form-label">品名选择：</label>
                        <div class="layui-input-inline">
                          <select id="typical" name="typical" lay-filter="typical" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <!-- typical 品名 -->
                          </select>
                        </div>
                      </div>
                    </div>
                    <div class="layui-form-item">
                      <div class="layui-inline">
                        <label class="layui-form-label">品牌选择：</label>
                        <div class="layui-input-inline">
                          <select id="brand" name="brand" lay-filter="brand" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <!-- brand 品牌-->
                          </select>
                        </div>
                      </div>
                    </div>
                    <div class="layui-form-item">
                      <div class="layui-inline">
                        <label class="layui-form-label">型号选择：</label>
                        <div class="layui-input-inline">
                          <select id="model" name="model" lay-filter="model" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <!-- model 型号 -->
                          </select>
                        </div>
                      </div>
                    </div>
                    <div class="layui-form-item">
                      <div style="width: 270px; margin: 0 auto 30px 35px;">
                        <button id="cityInventoryBtn" type="button" class="layui-btn layui-btn-fluid">开始盘点</button>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <!-- 县级仓库盘点 -->
              <!-- <div class="layui-colla-item">
                <h2 class="layui-colla-title">县级仓库盘点</h2>
                <div class="layui-colla-content">

                  <div class="layui-form">
                    <div class="layui-form-item">
                      <div class="layui-inline">
                        <label class="layui-form-label">选择县区：</label>
                        <div class="layui-input-inline">
                          <select name="modules" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value="1">郫县</option>
                            <option value="2">新津</option>
                            <option value="3">金牛</option>
                          </select>
                        </div>
                      </div>
                    </div>
                    <div class="layui-form-item">
                      <div class="layui-inline">
                        <label class="layui-form-label">选择年月：</label>
                        <div class="layui-input-inline">
                          <input type="text" class="layui-input" id="inventoryCountyDate" placeholder="yyyy-MM">
                        </div>
                      </div>
                    </div>
                    <div class="layui-form-item">
                      <div class="layui-inline">
                        <label class="layui-form-label">盘点类型：</label>
                        <div class="layui-input-inline">
                          <select name="modules" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value="1">终端</option>
                            <option value="2">设备</option>
                            <option value="3">物料</option>
                          </select>
                        </div>
                      </div>
                    </div>
                    <div class="layui-form-item">
                      <div style="width: 270px; margin: 0 auto 30px 35px;">
                        <button type="button" class="layui-btn layui-btn-fluid">开始盘点</button>
                      </div>
                    </div>
                  </div>
                </div>
              </div> -->
              <!-- 个人仓库盘点 -->
              <!-- <div class="layui-colla-item">
                <h2 class="layui-colla-title">个人仓库盘点</h2>
                <div class="layui-colla-content">

                  <div class="layui-form">
                    <div class="layui-form-item">
                      <div class="layui-inline layui-show-xs-block" style="width: 280px; margin-left: 35px;">
                        <input id="username" type="text" name="username" placeholder="输入姓名或工号查询员工仓库" autocomplete="off"
                          class="layui-input">
                      </div>
                      <div class="layui-inline layui-show-xs-block">
                        <button id="search" class="layui-btn" lay-submit="" lay-filter="sreach"><i
                            class="layui-icon">&#xe615;</i></button>
                      </div>
                      <table class="layui-table" style="width: 1100px; margin-left: 35px;">
                        <thead>
                          <tr>
                            <th>工号</th>
                            <th>姓名</th>
                            <th>性别</th>
                            <th>年龄</th>
                            <th>用户归属</th>
                            <th>操作</th>
                          </tr> 
                        </thead>
                        <tbody>
                          <tr>
                            <td>111</td>
                            <td>张三</td>
                            <td>女</td>
                            <td>32</td>
                            <td>郫县</td>
                            <td><button type="button" class="layui-btn layui-btn-primary layui-btn-sm">选择此人</button></td>
                          </tr>
                        </tbody>
                      </table>
                    </div>
                    <div class="layui-form-item">
                      <div class="layui-inline">
                        <label class="layui-form-label">选择年月：</label>
                        <div class="layui-input-inline">
                          <input type="text" class="layui-input" id="inventoryPersonalDate" placeholder="yyyy-MM">
                        </div>
                      </div>
                    </div>
                    <div class="layui-form-item">
                      <div class="layui-inline">
                        <label class="layui-form-label">盘点类型：</label>
                        <div class="layui-input-inline">
                          <select name="modules">
                            <option value="">直接选择或搜索选择</option>
                            <option value="1">终端</option>
                            <option value="2">设备</option>
                            <option value="3">物料</option>
                          </select>
                        </div>
                      </div>
                    </div>
                    <div class="layui-form-item">
                      <div style="width: 270px; margin: 0 auto 30px 35px;">
                        <button type="button" class="layui-btn layui-btn-fluid">开始盘点</button>
                      </div>
                    </div>
                  </div>
                </div>
              </div> -->
            </div>
            <!-- 盘点结果 -->
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
              <legend>盘点结果</legend>
            </fieldset>
            <table class="layui-table">
              <thead>
                <tr>
                  <th>品名</th>
                  <th>品牌</th>
                  <th>型号</th>
                  <th>入库数量</th>
                  <th>出库数量</th>
                  <th>消库数量</th>
                </tr>
              </thead>
              <tbody id="tbody">
                <tr>
                  <td>暂无</td>
                  <td>暂无</td>
                  <td>暂无</td>
                  <td>暂无</td>
                  <td>暂无</td>
                  <td>暂无</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>


  <!-- <script src="invenrotyCapcity.js"></script> -->
  <script src="../../lib/layui/layui.js" charset="utf-8"></script>
  <script>
    layui.use(['element', 'layer', 'form'], function () {
      var element = layui.element;
      var layer = layui.layer;
      var laydate = layui.laydate;
      var form = layui.form;

      //监听折叠
      element.on('collapse(test)', function (data) {
        layer.msg('展开状态：' + data.show);
      });

      // category种类选择
      $.ajax({
        url: app.ServerUrl + 'v1/type/getAllCategory',
        type: "get",
        contentType: "application/json;charset=UTF-8",
        dataType: "json",
        async: true,
        headers: {
          "Authorization": "460bcdb0-b326-4d6d-ac99-232c83ba6d80"
        },
        data: {},
        success: function (data) {
          // console.log(data.objs[0]);
          var categoryOptinons = "";
          var results = data.objs[0];
          $("#category").empty();
          // console.log($("#category"));
          for (var i = 0; i < results.length; i++) {
            categoryOptinons +=
              `
              <option value=${results[i].categoryId}>${results[i].categoryName}</option>
              `
          }
          // console.log(categoryOptinons);
          $("#category").append(categoryOptinons);
          form.render('select');
        },
        error: function (e) {
          console.log(e.statusText)
        }
      })

      // typical品名选择
      form.on('select(category)', function () {
        var managerId = app.getManagerId();
        var url = "";
        var categoryType = $("#category option:selected").val();
        // console.log(categoryType);
        if (categoryType == "1") {
          url = app.ServerUrl + 'v1/type/getTypicalNameByCategoryId/1?managerId=' + managerId;
        } else if (categoryType == "2") {
          url = app.ServerUrl + 'v1/type/getTypicalNameByCategoryId/2?managerId=' + managerId;
        } else {
          url = app.ServerUrl + 'v1/type/getTypicalNameByCategoryId/3?managerId=' + managerId;
        }

        $.ajax({
          url: url,
          type: "get",
          contentType: "application/json;charset=UTF-8",
          dataType: "json",
          async: true,
          headers: {
            "Authorization": "460bcdb0-b326-4d6d-ac99-232c83ba6d80"
          },
          data: {},
          success: function (data) {
            console.log(data.objs[0]);
            var results = data.objs[0];
            var typicalOptions = "";
            $("#typical").empty();
            // console.log($("#typical"));
            for (var i = 0; i < results.length; i++) {
              typicalOptions +=
                `
               <option>${results[i]}</option>
               `
            }
            // console.log(typicalOptions);
            $("#typical").append(typicalOptions);
            form.render('select');
          },
          error: function (e) {
            console.log(e.statusText)
          }
        })
      })

      // brand品牌选择
      var modelPos = [];
      form.on('select(typical)', function (data) {
        // console.log("brand品牌选择");
        var categoryId = $("#category option:selected").val();
        var managerId = app.getManagerId();
        var typicalName = $("#typical option:selected").val();

        $.ajax({
          url: app.ServerUrl + 'v1/type/getMaterialBrandAndModelPoByTypicalName/' +
            typicalName + "?managerId=" + managerId + "&categoryId=" + categoryId,
          type: "get",
          contentType: "application/json;charset=UTF-8",
          dataType: "json",
          async: true,
          headers: {
            "Authorization": "460bcdb0-b326-4d6d-ac99-232c83ba6d80"
          },
          data: {},
          success: function (data) {
            // console.log(data.objs[0]);
            var results = data.objs[0];
            var brandOptinons = "";
            $("#brand").empty();
            // console.log($("#brand"));
            for (var i = 0; i < results.length; i++) {
              modelPos.push(results[i].modelPo);
              brandOptinons +=
                `
              <option value="${i}">${results[i].brand}</option>
              `
            }
            // console.log(modelPos);
            $("#brand").append(brandOptinons);
            form.render('select');
          },
          error: function (e) {
            console.log(e.statusText)
          }
        })
      })

      // model型号选择
      form.on('select(brand)', function (data) {
        // console.log("model型号选择");
        var brandIndex = $("#brand option:selected").val();
        // console.log(brandIndex);
        var modelPo = modelPos[brandIndex];
        var modelOptinons = "";
        $("#model").empty();
        // console.log($("#model"));
        for (var i = 0; i < modelPo.length; i++) {
          modelOptinons +=
            `
              <option value="${modelPo[i].typicalId}">${modelPo[i].typicalModel}</option>
              `
        }
        // console.log(modelOptinons);
        $("#model").append(modelOptinons);
        form.render('select');
      })

      // 盘点ajax
      var info = null;
      var userGlobalInfo = app.getUserGlobalInfo();
      var managerGlobalInfo = app.getManagerGlobalInfo();
      if (userGlobalInfo) {
        info = userGlobalInfo;
      } else {
        info = managerGlobalInfo;
      }
      
      $("#cityInventoryBtn").click(function () {
        var repositoryId = info.repositoryList[0].repositoryId;
        // console.log(repositoryId);
        var typicalId = $("#model option:selected").val();
        // console.log(typicalId);
        if (repositoryId == "" || typicalId == "") {
          layer.msg("请先选择盘点信息！");
        } else {
          $.ajax({
            url: app.ServerUrl + 'repositoryLog/getRepositoryCapcity',
            type: "get",
            contentType: "application/json;charset=UTF-8",
            dataType: "json",
            async: true,
            headers: {
              "Authorization": "460bcdb0-b326-4d6d-ac99-232c83ba6d80"
            },
            data: {
              repositoryId: repositoryId,
              typicalId: typicalId
            },
            beforeSend: function () {
              loading = layer.load();
            },
            success: function (data) {
              layer.close(loading);
              // console.log(data.objs[0]);
              var results = data.objs[0];
              if (results.length == 0) {
                layer.msg('暂无记录');
              } else {
                $("#tbody").empty();;
                // console.log( $("#tbody"));

                var Nums = null;
                var Expand = null;
                var Destory = null;
                var str = '';

                for (var i = 0; i < results.length; i++) {
                  var item = results[i];
                  // console.log(item);

                  if (item.categoryId == "1") {
                    Nums = item.terminalNums;
                    Expand = item.terminalExpand;
                    Destory = item.terminalDestory;
                  } else if (item.categoryId == "2") {
                    Nums = item.equipmentNums;
                    Expand = item.equipmentExpand;
                    Destory = item.equipmentDestory;
                  } else {
                    Nums = item.stuffNums;
                    Expand = item.stuffExpand;
                    Destory = item.stuffDestory;
                  }
                  str +=
                    `<tr>
              <td>${item.typicalName}</td>
              <td>${item.brand}</td>
              <td>${item.typicalModel}</td>
              <td>${Nums}</td>
              <td>${Expand}</td>
              <td>${Destory}</td>
            </tr>`
                }
                // console.log(str);

                $("#tbody").append(str);
              }
            },
            error: function (e) {
              console.log(e.statusText)
            }
          })
        }

      })
    });
  </script>
  <script>
    //百度统计可去掉
    var _hmt = _hmt || [];
    (function () {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>
</body>

</html>